function clicked(oEvent){
    var current, inp;
    inp = document.getElementById('calcinput');
    /*
    if(oEvent.target.getTextContent == null){
        oEvent.target.setTextContent('qwerty');
    }
    */
    if(oEvent.target == '[object HTMLTableElement]'){
        //alert('TABLE');
    } else if(oEvent.target.textContent == 'C'){
        inp.value = '';
    } else if(oEvent.target.textContent == 'Calculate'){

        //POST AJAX
        $.ajax({
            type: 'POST',
            url: 'calc_service.php',
            data: { calcme: inp.value },
            cache: false,
            success: function(html){
                inp.value = html;
            }
        });
    } else if(oEvent.target.textContent == 'sin' || oEvent.target.textContent == 'cos' || oEvent.target.textContent == '√' || oEvent.target.textContent == 'log'){
        pro_mode(oEvent.target.textContent);
    } else if(oEvent.target == '[object HTMLInputElement]'){
        //alert('INPUT');
    } else {
        inp = document.getElementById('calcinput');
        current = oEvent.target.textContent;
        inp.value = inp.value + current;
    }            

}

function pro_mode(ans){
    inp = document.getElementById('calcinput');
    if(inp.value == ''){ alert('Мгновенно вычисляет ' + ans + ' для числа в поле ввода.'); }
    if(ans == '√'){ ans = 'qad'; }
    var url  = 'calc_service.php?pro&' + ans + '=' + inp.value;
    $.ajax({
        url: 'calc_service.php?pro&' + ans + '=' + inp.value,
        cache: false,
        success: function(html){
            inp.value = html;
        }
    });
}

function repeat(id){
    inp = document.getElementById('calcinput');
    $.ajax({
        type: 'GET',
        url: 'calc_service.php?id=' + id,
        cache: false,
        success: function(html){
            inp.value = html;
        }
    });
}

function showHistory(){
    $.ajax({
        url: 'calc_service.php?history',
        cache: false,
        success: function(html){
            $("#history").html(html);
        }
    });
}


